import React, { Component } from 'react'
import './index.css'

export default class Footer extends Component {

  handleCheckedAll = (e) => {
    this.props.checkedall(e.target.checked)
  }

  hanleClearAllDone = () => {
    this.props.clearAlldone()
  }

  render() {
    let {todos,checkedall,clearAlldone} = this.props

    const count = todos.reduce((pre, todo) => {
      return pre + (todo.done? 1 : 0)
    }, 0)
    
    const total = todos.length
    

    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" checked={count == total&&total!==0? true: false} onChange={this.handleCheckedAll} />
        </label>
        <span>
          <span>已完成{count}</span> / 全部{total}
        </span>
        <button className="btn btn-danger" onClick={this.hanleClearAllDone} >清除已完成任务</button>
      </div>
    )
  }
}
